/*
多态
https://www.bilibili.com/video/BV1gf4y1r79E/?p=20&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

// 一说：接口本质是一个指针
type AnimalInterface interface {
	Sleep()
	GetColor() string // 获取动物的颜色
	GetType() string  // 获取动物的种类
}

// 具体的类1
type Cat struct {
	color string // 猫的颜色
}

func (this *Cat) Sleep() {
	fmt.Println("Cat is Sleep")
}

func (this *Cat) GetColor() string {
	return this.color
}

func (this *Cat) GetType() string {
	return "Cat"
}

// 具体的类2
type Dog struct {
	color string // 狗的颜色
}

func (this *Dog) Sleep() {
	fmt.Println("Dog is Sleep")
}

func (this *Dog) GetColor() string {
	return this.color
}

func (This Dog) GetType() string {
	return "Dog"
}

func polyDemo(animal AnimalInterface) {
	animal.Sleep()
	fmt.Println(animal.GetColor())
	fmt.Println(animal.GetType())
}

func main() {
	fmt.Println("polymorphism")

	// 接口数据类型
	var animal1 AnimalInterface
	animal1 = &Cat{"Green"}
	animal1.Sleep()

	var animal2 AnimalInterface
	animal2 = &Dog{"yellow"}
	animal2.Sleep()

	fmt.Println("====================")

	polyDemo(animal1)
	polyDemo(animal2)
}
